package com.logic.landseaserver.models.refunddiary.ws;

import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.logic.common.enums.HttpCodeEnum;
import com.logic.common.util.CommonResult;
import com.logic.common.util.CommonResultMap;
import com.logic.common.util.QueryUtil;
import com.logic.landseaserver.models.refunddiary.bean.RefundRecordResp;
import com.logic.landseaserver.models.refunddiary.service.RefundDiaryService;
import com.logic.landseaserver.ws.BillRecordRest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@Path("/refundDiary")
@Api(value = "退款日记账")
public class RefundDiaryRest
{
    private static final Logger logger = LoggerFactory.getLogger(BillRecordRest.class);
    
    @Autowired
    private RefundDiaryService refundDiaryService;
    
    @Autowired
    HttpServletRequest httpServletRequest;
    
    @POST
    @Path("/refundDiaryList")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "退款日记账列表")
    public Response refundRecordList(@ApiParam(value = "param", required = true) QueryUtil queryUtil)
    {
        CommonResultMap map = new CommonResultMap();
        try
        {
            queryUtil.getPagingTool().calculateStartIndex();
            List<RefundRecordResp> result = refundDiaryService.getRefundRecordList(queryUtil);
            Integer totalCount = queryUtil.getPagingTool().getTotalNum();
            map.setResultTotalCount(totalCount);
            map.setData(result);
            map.setResult(CommonResult.SUCCESS);
        }
        catch (Exception e)
        {
            logger.error("refundRecord || refundRecordList error.", e);
            map.setResult(CommonResult.ERROR, e.getMessage());
        }
        return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
    }
    
    @POST
    @Path("/downloadRefundRecordExcel")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "下载退款日记账列表excel")
    public Response downloadRefundRecordExcel(@ApiParam(value = "param", required = true) QueryUtil queryUtil)
    {
        CommonResultMap map = new CommonResultMap();
        try
        {
            String url = refundDiaryService.downloadRefundRecordExcel(queryUtil);
            HashMap<String, String> resultmap = new HashMap<String, String>();
            resultmap.put("url", url);
            map.setData(resultmap);
            map.setResult(CommonResult.SUCCESS);
        }
        catch (Exception e)
        {
            logger.error("refundRecord || refundRecordList error.", e);
            map.setResult(CommonResult.ERROR, e.getMessage());
        }
        return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
    }
    
}
